/* Copyright (c) 2003-2008 GD GameDuell GmbH, All Rights Reserved
 * This document is strictly confidential and sole property of GD GameDuell GmbH, Berlin, Germany
 */

package de.gameduell.framework.geom {
	import flash.display.DisplayObjectContainer;	
	import flash.geom.Point;
	
	/**
	 * @author Gevorg Sargsyan
	 */
	public class BezierList {
		/** contains all the QuadraticBezier curves*/
		protected var _bezierList:Array;
		
		/**
		 * constructor
		 * creates the bezierList
		 */
		public function BezierList() {
			_bezierList = new Array();
		}
		
		/**
		 * use this function to add a curve to the list
		 * 
		 * @param bezier curve to add to
		 */
		public function push(bezier:QuadraticBezier):void{
			_bezierList.push(bezier);
		}
		
		public function reset():void{
			clear();
			_bezierList = new Array();	
		}
		
		/**
		 * returns a position on the _bezierList
		 * 
		 * examples:
		 * 1. getPosition(0) 	would return the startPoint of the first curve
		 * 2. getPosition(1) 	would return the endPoint of the last curve
		 * 
		 * @param a value between 0 and 1 
		 * 
		 * @return a postion on the _bezierList
		 */
		public function getPosition(time:Number):Point{	
			if(_bezierList.length == 0){
				return new Point(0,0);
			}
			var timeScale:Number = _bezierList.length * time;	
			var index:Number 	 = Math.floor(timeScale);
			
			return _bezierList[index].getPosition(timeScale-index);
		}
		
		/**
		 * draws all the curves in the list
		 */
		public function draw(container : DisplayObjectContainer) : void {
			for(var i:* in _bezierList){
				_bezierList[i].draw(container);
			}
		}
		
		public function clear():void{
			for(var i:* in _bezierList){
				_bezierList[i].clear();
			}
		}		
		
	}
}
